package com.medical.data.utils;

import com.alibaba.fastjson2.JSONArray;
import com.medical.data.domain.FormData;
import org.junit.jupiter.api.Test;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson2.JSONObject;
import java.util.List;

@Component
public class FormDataJsonUtils {
    @Test
    public List<FormData> FormDataJson(String scheme){
        return null;
    }

    @Test
    public void test(){
        String scheme = "{\"config\":{\"version\":\"0.5\",\"formRef\":\"elForm\",\"formModel\":\"form\",\"rules\":\"rules\",\"size\":\"default\",\"labelPosition\":\"right\",\"labelWidth\":80,\"formRules\":\"rules\",\"gutter\":15,\"disabled\":false,\"dynamicTableAllowed\":true},\"list\":[{\"id\":\"fd_1709627511845\",\"_id\":\"fd_1709627511845\",\"compType\":\"input\",\"ele\":\"el-input\",\"compName\":\"单行文本\",\"compIcon\":\"input\",\"viewType\":\"text\",\"config\":true,\"showLabel\":true,\"label\":\"单行文本\",\"labelWidth\":80,\"placeholder\":\"请输入文本\",\"required\":false,\"maxLength\":50,\"gutter\":15,\"span\":24,\"width\":\"100%\",\"clearable\":true,\"disabled\":false,\"readonly\":false,\"status\":\"normal\",\"prefix-icon\":\"\",\"suffix-icon\":\"\",\"modelValue\":\"\",\"rules\":[],\"rulesType\":\"default\",\"prepend\":\"\",\"append\":\"\",\"layout\":\"colItem\"},{\"id\":\"fd_1709627518282\",\"_id\":\"fd_1709627518282\",\"compType\":\"radio\",\"compName\":\"单选框\",\"ele\":\"el-radio-group\",\"compIcon\":\"radio\",\"viewType\":\"component\",\"config\":true,\"label\":\"单选框\",\"placeholder\":\"请选择\",\"maxLength\":50,\"span\":24,\"gutter\":15,\"labelWidth\":80,\"showLabel\":true,\"required\":false,\"disabled\":false,\"border\":false,\"vertical\":false,\"size\":\"default\",\"optionType\":\"default\",\"options\":[{\"label\":\"选项一\",\"value\":1},{\"label\":\"选项二\",\"value\":2}],\"dataType\":\"static\",\"action\":\"https://www.fastmock.site/mock/51715c0157535b99010bde55f2df33c8/formDesigner/api/options\",\"modelValue\":\"\",\"rules\":[],\"ruleError\":\"该字段不能为空\",\"layout\":\"colItem\"}]}";

        JSONObject jsonObject = JSONObject.parseObject(scheme);
        if (jsonObject.containsKey("config")) {
            JSONObject configObject = jsonObject.getJSONObject("config");
            System.out.println(configObject);
        } else {
            System.out.println("No 'config' field found in the JSON data.");
        }

        if (jsonObject.containsKey("list")) {
            JSONArray listArray = jsonObject.getJSONArray("list");
            for (int i = 0; i < listArray.size(); i++) {
                JSONObject listItem = listArray.getJSONObject(i);
                String compType= listItem.getString("compType");
                System.out.println("Item " + (i+1) + ": " + compType);
            }
        } else {
            System.out.println("No 'list' field found in the JSON data.");
        }
    }

}
